<html>
<head><meta charset="utf-8"><title>Snippets don&#x27;t work in assists · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html">Snippets don&#x27;t work in assists</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232008542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232008542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232008542">(Mar 26 2021 at 18:02)</a>:</h4>
<p>I'm trying to make an assist insert snippets, but they seem to be interpreted as normal text. Is this not supported?</p>



<a name="232008631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232008631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232008631">(Mar 26 2021 at 18:02)</a>:</h4>
<p>It looks like extract_function is also <em>trying</em> to do this, but that also doesn't work for me</p>



<a name="232008715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232008715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232008715">(Mar 26 2021 at 18:03)</a>:</h4>
<p>I think I just ran into this on "extract variable"</p>



<a name="232009082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232009082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232009082">(Mar 26 2021 at 18:05)</a>:</h4>
<p>huh, according to the LSP spec snippets are only for completion? do we have to use <code>ChangeAnnotation</code> in assists?</p>



<a name="232009691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232009691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232009691">(Mar 26 2021 at 18:10)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> snippents in assists are our custom extension</p>



<a name="232009717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232009717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232009717">(Mar 26 2021 at 18:10)</a>:</h4>
<p>oh</p>



<a name="232009768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232009768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232009768">(Mar 26 2021 at 18:11)</a>:</h4>
<p>They are almost as hacky as inlay hints, so they might got boroken by something</p>



<a name="232009924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232009924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232009924">(Mar 26 2021 at 18:12)</a>:</h4>
<p>I'll open an issue</p>



<a name="232010167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010167">(Mar 26 2021 at 18:14)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/issues/8208">https://github.com/rust-analyzer/rust-analyzer/issues/8208</a></p>



<a name="232010292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010292">(Mar 26 2021 at 18:15)</a>:</h4>
<p>hmm, but if they work like completion snippets <code>$0</code> indicates the final cursor position, not that the token at that position is actually a snippet</p>



<a name="232010388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010388">(Mar 26 2021 at 18:16)</a>:</h4>
<p>setting the cursor position also doesn't always work right though</p>



<a name="232010612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010612">(Mar 26 2021 at 18:18)</a>:</h4>
<p>This works fine for me <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="232010799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010799">(Mar 26 2021 at 18:20)</a>:</h4>
<p>I'm on VS Code 1.54.2</p>



<a name="232010939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232010939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232010939">(Mar 26 2021 at 18:20)</a>:</h4>
<p>I'm on 1.54.3</p>



<a name="232013048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232013048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232013048">(Mar 26 2021 at 18:36)</a>:</h4>
<p>hmm, no, doesn't work right after updating to that version either</p>



<a name="232098783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232098783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232098783">(Mar 27 2021 at 15:49)</a>:</h4>
<p>A bit late, but I found that <code>placeholderLength</code> always equals zero. I'm not even sure whether it worked before or not, since snippets that we are providing to clients (at least in cases like <code>let $0var_name = 123;</code>) doesn't contain any info about how much client should select</p>



<a name="232098846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232098846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ivan770 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232098846">(Mar 27 2021 at 15:50)</a>:</h4>
<p>Client <em>could</em> guess that it has to select next word however</p>



<a name="232101106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232101106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232101106">(Mar 27 2021 at 16:27)</a>:</h4>
<p>yeah, now I'm not sure either</p>



<a name="232101438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232101438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232101438">(Mar 27 2021 at 16:32)</a>:</h4>
<p>I don't think they're supposed to select anything in that case, just put the cursor there</p>



<a name="232101618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232101618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232101618">(Mar 27 2021 at 16:34)</a>:</h4>
<p>there's other cases like the "Generate function" assist where it does select something</p>



<a name="232101966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232101966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232101966">(Mar 27 2021 at 16:41)</a>:</h4>
<p>I think it doesn't handle multi-line edits well, and also doesn't support multiple snippets in the same set of text edits</p>



<a name="232102082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232102082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232102082">(Mar 27 2021 at 16:44)</a>:</h4>
<p>hmm, maybe multi-line edits are fine, but multiple TextEdits are what confuses it</p>



<a name="232102140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232102140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232102140">(Mar 27 2021 at 16:44)</a>:</h4>
<p>because it just puts my cursor somewhere between the 2 edits</p>



<a name="232106529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Snippets%20don%27t%20work%20in%20assists/near/232106529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Snippets.20don&#x27;t.20work.20in.20assists.html#232106529">(Mar 27 2021 at 17:53)</a>:</h4>
<p>managed to fix it, at least partially</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>